<?php
global $_W,$_GPC;
include MODULE_ROOT.'/inc/mobile/__init.php';
$rid = intval($_GPC['rid']);
$weid = $_W['uniacid'];
die("请用人脸签到");
if($_W['isajax']){
	$openid = $_W['openid'];
	$realname = $_GPC['realname'];
	$mobile = $_GPC['mobile'];
	$deptname = $_GPC['deptname'];
	
	$check = pdo_fetchcolumn("SELECT `mobile` FROM ".tablename($this->user_table)." WHERE weid=:weid AND rid=:rid AND openid = :openid",array(':weid'=>$weid,':rid'=>$rid,':openid'=>$openid));
	if($rid && !empty($openid) && empty($check)){
		$check_realname = pdo_fetchcolumn("SELECT `id` FROM ".tablename($this->user_table)." WHERE weid=:weid AND rid=:rid AND (mobile=:mobile AND realname=:realname)",array(':weid'=>$weid,':rid'=>$rid,':mobile'=>$_GPC['mobile'],':realname'=>$realname));
		if($check_realname){
			//die(json_encode(error(-1,'您已经签过到了，请勿重复签到！')));
		}
		pdo_update($this->user_table,array('mobile'=>$mobile,'realname'=>$realname,'nick_name'=>$realname,'deptname'=>$deptname),array('weid'=>$weid,'rid'=>$rid,'openid'=>$openid));
		$status = pdo_fetchcolumn("SELECT `status` FROM ".tablename($this->qd_config_table)." WHERE weid=:weid AND rid=:rid",array(':weid'=>$weid,':rid'=>$rid));
		if($status=='2'){
			$level = 2;
		}else{
			$level = 1;
		}
		$data = array('weid'=>$weid,'rid'=>$rid,'nick_name'=>$user['nick_name'],'openid'=>$openid,'avatar'=>$user['avatar'],'level'=>$level,'createtime'=>time());
		pdo_insert($this->qd_table,$data);
		$qd_id = pdo_insertid();
		$qd = pdo_fetch("SELECT * FROM ".tablename($this->qd_table)." WHERE weid = :weid  AND id = :id",array(':weid'=>$weid,':id'=>$qd_id));
		die(json_encode(error(0,'success')));
	}else{
		die(json_encode(error(0,'success')));
	}
}